package com.wing.res.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wing.common.exception.BusinessException;
import com.wing.res.dao.ResProductDrawPicDao;

import com.wing.res.model.entity.ResProductDrawPic;

import com.wing.res.model.response.ResProductDrawPicVo;
import com.wing.res.service.ResProductDrawPicService;

import com.wing.web.excel.DrawPicExcelIn;
import com.wing.web.utils.JwtUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class ResProductDrawPicServiceImpl extends ServiceImpl<ResProductDrawPicDao, ResProductDrawPic> implements ResProductDrawPicService {


    /**
     * 查询图纸列表
     *
     * @param pg
     * @return
     */

    @Override
    public Page<ResProductDrawPicVo> getListByMap(Page<ResProductDrawPicVo> pg, Map<String, Object> map) {
        return this.baseMapper.getListByMap(pg, map);
    }

    @Override
    public void importExcel(List<DrawPicExcelIn> list) {
        int i = 1;
        for (DrawPicExcelIn productDetail : list) {
            if (StringUtils.isBlank(productDetail.getName())) {
                throw new BusinessException(300, "第" + i + "行【名称】未输入数据");
            }
            if (StringUtils.isBlank(productDetail.getFileUrl())) {
                throw new BusinessException(300, "第" + i + "行【图片地址】未输入数据");
            }

            ResProductDrawPic drawPic=new ResProductDrawPic();
            drawPic.setName(productDetail.getName());
            drawPic.setFileUrl(productDetail.getFileUrl());
            baseMapper.insert(drawPic);
        }



    }

}
